
************** This program generates the results in Table A4 of the paper: respondent unemployment shock as outcome variable *************


clear all
set more off, permanently
cd "$localdir\Data"
global output "$localdir\Output"




***************************************************** RESPONDENT UNEMPLOYMENT SHOCK YEAR OF SURVEY ******************************************************

log using "$output\RF - collapsed - i Unemployment t.smcl", replace


*** Dataset with respondent unemployment (unique respondent-year observations)
use registerdata19802012_us, clear

keep pnr year grossunemp

duplicates drop pnr year, force

bysort pnr (year): g grossunemp_lag=grossunemp[_n-1] if year==year[_n-1]+1
g grossunemp_enter=(grossunemp==1 & grossunemp_lag==0) if grossunemp!=. & grossunemp_lag!=.

bysort pnr (year): g grossunemp_enter_lead=grossunemp_enter[_n+1] 

bysort pnr (year): g grossunemp_enter_lead2=grossunemp_enter[_n+2] 

replace year=year+1 // To match survey year

*** Merge in the unique identifier
merge m:1 pnr using "Unique ID (pnr).dta"
keep if _merge==3
keep unique year grossunemp_enter_lead grossunemp_enter_lead2

save "Respondent Unemployment", replace

*** Respondent unemployment dataset saved

use "Voting RF for Analysis - Last Year.dta", clear

merge m:1 unique year using "Respondent Unemployment"
keep if _merge==3
drop _merge

keep if grossunemp_enter_lead!=. & grossunemp_enter_network!=.

* Collapse
bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

* Results
display c(current_time)
reg grossunemp_enter_lead grossunemp_enter_network_share, cluster(muni)
sum grossunemp_enter_lead if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock same year") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, NO, Industry-Year, NO, Occupation-Year, NO, Education-Year, NO)

reghdfe grossunemp_enter_lead grossunemp_enter_network_share, absorb(both) cluster(muni)
sum grossunemp_enter_lead if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock same year") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, NO, Occupation-Year, NO, Education-Year, NO)

reghdfe grossunemp_enter_lead grossunemp_enter_network_share, absorb(both ind2_year) cluster(muni)
sum grossunemp_enter_lead if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock same year") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, YES, Occupation-Year, NO, Education-Year, NO)

reghdfe grossunemp_enter_lead grossunemp_enter_network_share, absorb(both ind2_year ocp_year) cluster(muni)
sum grossunemp_enter_lead if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock same year") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, YES, Occupation-Year, YES, Education-Year, NO)

reghdfe grossunemp_enter_lead grossunemp_enter_network_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum grossunemp_enter_lead if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock same year") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, YES, Occupation-Year, YES, Education-Year, YES)

display c(current_time)






***************************************************** RESPONDENT UNEMPLOYMENT SHOCK YEAR AFTER SURVEY ******************************************************

log using "$output\RF - collapsed - i Unemployment t+1.smcl", replace

use "Voting RF for Analysis - Last Year.dta", clear

merge m:1 unique year using "Respondent Unemployment"
keep if _merge==3
drop _merge

keep if grossunemp_enter_lead2!=. & grossunemp_enter_network!=.

* Collapse
bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

* Results
display c(current_time)
reg grossunemp_enter_lead2 grossunemp_enter_network_share, cluster(muni)
sum grossunemp_enter_lead2 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock year after") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, NO, Industry-Year, NO, Occupation-Year, NO, Education-Year, NO)

reghdfe grossunemp_enter_lead2 grossunemp_enter_network_share, absorb(both) cluster(muni)
sum grossunemp_enter_lead2 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock year after") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, NO, Occupation-Year, NO, Education-Year, NO)

reghdfe grossunemp_enter_lead2 grossunemp_enter_network_share, absorb(both ind2_year) cluster(muni)
sum grossunemp_enter_lead2 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock year after") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, YES, Occupation-Year, NO, Education-Year, NO)

reghdfe grossunemp_enter_lead2 grossunemp_enter_network_share, absorb(both ind2_year ocp_year) cluster(muni)
sum grossunemp_enter_lead2 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock year after") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, YES, Occupation-Year, YES, Education-Year, NO)

reghdfe grossunemp_enter_lead2 grossunemp_enter_network_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum grossunemp_enter_lead2 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA4.xls", append nocons nor ctitle("Unemployment shock year after") bdec(3) sdec(3) adec(3) label ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock') ///
addt(Parish-Year FE, YES, Industry-Year, YES, Occupation-Year, YES, Education-Year, YES)

display c(current_time)









